|
RAIS
3.2
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Text; 00004 using NUnit.Framework; 00005 using RAIS.Common.TableManagement; 00006 using RAIS.DataAccessLayer; 00007 using TableTypes = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Table.TableTypeData>; 00008 using TableGroups = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.TableGroup>; 00009 using Tables = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Table>; 00010 using Fields = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Field>; 00011 using FieldSizes = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Field.FieldSizeData>; 00012 00013 namespace RAIS.DataAccessLayerTest 00014 { 00015 [TestFixture] 00016 public class TableManagementTest 00017 { 00018 TableGroup tableGroup; 00019 00020 [SetUp] 00021 public void Init() 00022 { 00023 //TestUtilities.TruncateTable("Field"); 00024 //TestUtilities.TruncateTable("Table"); 00025 TestUtilities.DeleteTestTables(); 00026 00027 this.tableGroup = new TableGroup(); 00028 } 00029 //********************************************************************* 00030 #region Properties 00031 [Test] 00032 public void TableGroups_Count() 00033 { 00034 // Preparations 00035 int expectedCount = 11; 00036 00037 // Test 00038 Assert.AreEqual(expectedCount, TableManagement.TableGroups.Count); 00039 } 00040 [Test] 00041 public void TableGroups_AssociatedEquipments() 00042 { 00043 // Preparations 00044 int expectedID = 1; 00045 string expectedName = "Associated Equipments"; 00046 bool expectedAccepted = true; 00047 00048 // Test 00049 this.tableGroup = TableManagement.TableGroups[expectedName]; 00050 00051 // Checks 00052 Assert.AreEqual(expectedID, this.tableGroup.ID); 00053 Assert.AreEqual(expectedName, this.tableGroup.Name); 00054 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00055 } 00056 [Test] 00057 public void TableGroups_Authorizations() 00058 { 00059 // Preparations 00060 int expectedID = 2; 00061 string expectedName = "Authorizations"; 00062 bool expectedAccepted = true; 00063 00064 // Test 00065 this.tableGroup = TableManagement.TableGroups[expectedName]; 00066 00067 // Checks 00068 Assert.AreEqual(expectedID, this.tableGroup.ID); 00069 Assert.AreEqual(expectedName, this.tableGroup.Name); 00070 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00071 } 00072 [Test] 00073 public void TableGroups_CommonTables() 00074 { 00075 // Preparations 00076 int expectedID = 3; 00077 string expectedName = "Common Tables"; 00078 bool expectedAccepted = true; 00079 00080 // Test 00081 this.tableGroup = TableManagement.TableGroups[expectedName]; 00082 00083 // Checks 00084 Assert.AreEqual(expectedID, this.tableGroup.ID); 00085 Assert.AreEqual(expectedName, this.tableGroup.Name); 00086 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00087 } 00088 [Test] 00089 public void TableGroups_Enforcement() 00090 { 00091 // Preparations 00092 int expectedID = 4; 00093 string expectedName = "Enforcement"; 00094 bool expectedAccepted = true; 00095 00096 // Test 00097 this.tableGroup = TableManagement.TableGroups[expectedName]; 00098 00099 // Checks 00100 Assert.AreEqual(expectedID, this.tableGroup.ID); 00101 Assert.AreEqual(expectedName, this.tableGroup.Name); 00102 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00103 } 00104 [Test] 00105 public void TableGroups_FacilitiesAndAuthorities() 00106 { 00107 // Preparations 00108 int expectedID = 5; 00109 string expectedName = "Facilities and Authorities"; 00110 bool expectedAccepted = true; 00111 00112 // Test 00113 this.tableGroup = TableManagement.TableGroups[expectedName]; 00114 00115 // Checks 00116 Assert.AreEqual(expectedID, this.tableGroup.ID); 00117 Assert.AreEqual(expectedName, this.tableGroup.Name); 00118 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00119 } 00120 [Test] 00121 public void TableGroups_Incidents() 00122 { 00123 // Preparations 00124 int expectedID = 6; 00125 string expectedName = "Incidents"; 00126 bool expectedAccepted = true; 00127 00128 // Test 00129 this.tableGroup = TableManagement.TableGroups[expectedName]; 00130 00131 // Checks 00132 Assert.AreEqual(expectedID, this.tableGroup.ID); 00133 Assert.AreEqual(expectedName, this.tableGroup.Name); 00134 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00135 } 00136 [Test] 00137 public void TableGroups_Inspections() 00138 { 00139 // Preparations 00140 int expectedID = 7; 00141 string expectedName = "Inspections"; 00142 bool expectedAccepted = true; 00143 00144 // Test 00145 this.tableGroup = TableManagement.TableGroups[expectedName]; 00146 00147 // Checks 00148 Assert.AreEqual(expectedID, this.tableGroup.ID); 00149 Assert.AreEqual(expectedName, this.tableGroup.Name); 00150 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00151 } 00152 [Test] 00153 public void TableGroups_Persons() 00154 { 00155 // Preparations 00156 int expectedID = 8; 00157 string expectedName = "Persons"; 00158 bool expectedAccepted = true; 00159 00160 // Test 00161 this.tableGroup = TableManagement.TableGroups[expectedName]; 00162 00163 // Checks 00164 Assert.AreEqual(expectedID, this.tableGroup.ID); 00165 Assert.AreEqual(expectedName, this.tableGroup.Name); 00166 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00167 } 00168 [Test] 00169 public void TableGroups_RadiationGenerators() 00170 { 00171 // Preparations 00172 int expectedID = 9; 00173 string expectedName = "Radiation Generators"; 00174 bool expectedAccepted = true; 00175 00176 // Test 00177 this.tableGroup = TableManagement.TableGroups[expectedName]; 00178 00179 // Checks 00180 Assert.AreEqual(expectedID, this.tableGroup.ID); 00181 Assert.AreEqual(expectedName, this.tableGroup.Name); 00182 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00183 } 00184 [Test] 00185 public void TableGroups_SealedSources() 00186 { 00187 // Preparations 00188 int expectedID = 10; 00189 string expectedName = "Sealed Sources"; 00190 bool expectedAccepted = true; 00191 00192 // Test 00193 this.tableGroup = TableManagement.TableGroups[expectedName]; 00194 00195 // Checks 00196 Assert.AreEqual(expectedID, this.tableGroup.ID); 00197 Assert.AreEqual(expectedName, this.tableGroup.Name); 00198 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00199 } 00200 [Test] 00201 public void TableGroups_UnsealedSources() 00202 { 00203 // Preparations 00204 int expectedID = 11; 00205 string expectedName = "Unsealed Sources"; 00206 bool expectedAccepted = true; 00207 00208 // Test 00209 this.tableGroup = TableManagement.TableGroups[expectedName]; 00210 00211 // Checks 00212 Assert.AreEqual(expectedID, this.tableGroup.ID); 00213 Assert.AreEqual(expectedName, this.tableGroup.Name); 00214 Assert.AreEqual(expectedAccepted, this.tableGroup.Accepted); 00215 } 00216 #endregion 00217 //********************************************************************* 00218 #region Public Methods 00219 [Test] 00220 public void SaveTableGroup() 00221 { 00222 // Preparations 00223 string name = "Associated Equipments"; 00224 string errorMessage = ""; 00225 bool expectedAccepted; 00226 TableGroups tableGroups; 00227 TableGroup tableGroup; 00228 00229 // Save Accsepted = false 00230 // Preparations 00231 tableGroups = TableManagement.TableGroups; 00232 tableGroup = tableGroups[name]; 00233 expectedAccepted = false; 00234 tableGroup.Accepted = expectedAccepted; 00235 00236 // Test 00237 TableManagement.SaveTableGroup(tableGroup, ref errorMessage); 00238 00239 // Checks 00240 tableGroups = TableManagement.TableGroups; 00241 tableGroup = tableGroups[name]; 00242 Assert.AreEqual(expectedAccepted, tableGroup.Accepted); 00243 00244 // Save Accsepted = true 00245 // Preparations 00246 tableGroups = TableManagement.TableGroups; 00247 tableGroup = tableGroups[name]; 00248 expectedAccepted = true; 00249 tableGroup.Accepted = expectedAccepted; 00250 00251 // Test 00252 TableManagement.SaveTableGroup(tableGroup, ref errorMessage); 00253 00254 //Checks 00255 tableGroups = TableManagement.TableGroups; 00256 tableGroup = tableGroups[name]; 00257 Assert.AreEqual(expectedAccepted, tableGroup.Accepted); 00258 } 00259 [Test] 00260 public void AddTable() 00261 { 00262 /*// Preparations 00263 string expectedTableName = "Test Table"; 00264 string expectedGroupName = "Associated Equipments"; 00265 string expectedTableTypeVisibleName = "Single"; 00266 Table.TableType expectedTableType = Table.TableType.Single; 00267 bool expectedCustomTable = false; 00268 string errorMessage = ""; 00269 bool returnCode; 00270 00271 TableGroups tableGroups = TableManagement.TableGroups; 00272 TableGroup tableGroup = tableGroups[expectedGroupName]; 00273 00274 Table table = new Table(); 00275 table.Name = expectedTableName; 00276 table.TypeText = expectedTableTypeVisibleName; 00277 table.CustomTable = expectedCustomTable; 00278 00279 // Test 00280 returnCode = TableManagement.AddTable(table, tableGroup, ref errorMessage); 00281 00282 Assert.IsTrue(returnCode); 00283 00284 // Checks 00285 Tables tables = TableManagement.GetTablesByTableGroup(tableGroup); 00286 Table checkTable = tables[expectedTableName]; 00287 00288 Assert.AreEqual(expectedTableName, checkTable.Name); 00289 Assert.AreEqual(expectedTableType, checkTable.Type); 00290 Assert.AreEqual(expectedCustomTable, checkTable.CustomTable); 00291 00292 // Restore to the previos state 00293 returnCode = TableManagement.RemoveTable(checkTable, ref errorMessage); 00294 00295 Assert.IsTrue(returnCode);*/ 00296 } 00297 [Test] 00298 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))] 00299 public void RemoveTable() 00300 { 00301 /*// Preparations 00302 string expectedTableName = "Test Table"; 00303 string expectedGroupName = "Associated Equipments"; 00304 string expectedTableTypeVisibleName = "Single"; 00305 string errorMessage = ""; 00306 bool returnCode; 00307 00308 TableGroups tableGroups = TableManagement.TableGroups; 00309 TableGroup tableGroup = tableGroups[expectedGroupName]; 00310 00311 Table table = new Table(); 00312 table.Name = expectedTableName; 00313 table.TypeText = expectedTableTypeVisibleName; 00314 00315 TableManagement.AddTable(table, tableGroup, ref errorMessage); 00316 00317 // Test 00318 returnCode = TableManagement.RemoveTable(table, ref errorMessage); 00319 00320 // Checks 00321 Assert.IsTrue(returnCode); 00322 00323 // Check that field does not exist in table fields 00324 // Expected exception System.Collections.Generic.KeyNotFoundException 00325 Tables tables = TableManagement.GetTablesByTableGroup(tableGroup); 00326 Table checkTable = tables[expectedTableName];*/ 00327 } 00328 /*[Test] 00329 public void GetTablesByTableGroup() 00330 { 00331 // Preparations 00332 int expectedCount = 3; 00333 string[] expectedTableNames = { "Test Table 1", "Test Table 2", "Test Table 3" }; 00334 string expectedGroupName = "Associated Equipments"; 00335 string[] expectedTableTypeVisibleNames = { "Single", "With History", "Authorization" }; 00336 Table.TableType[] expectedTableTypes = { 00337 Table.TableType.Single 00338 , Table.TableType.WithHistory 00339 , Table.TableType.Authorization 00340 }; 00341 string errorMessage = ""; 00342 bool returnCode; 00343 00344 TableGroups tableGroups = TableManagement.TableGroups; 00345 TableGroup tableGroup = tableGroups[expectedGroupName]; 00346 00347 Table[] tables = new Table[expectedCount]; 00348 for (int i = 0; i < expectedCount; i++ ) 00349 { 00350 tables[i] = new Table(); 00351 tables[i].Name = expectedTableNames[i]; 00352 tables[i].TypeText = expectedTableTypeVisibleNames[i]; 00353 TableManagement.AddTable(tables[i], tableGroup, ref errorMessage); 00354 } 00355 00356 // Test 00357 Tables checkedTabels = TableManagement.GetTablesByTableGroup(tableGroup); 00358 00359 // Checks 00360 //Assert.AreEqual(expectedCount, checkedTabels.Count); 00361 for (int i = 0; i < expectedCount; i++) 00362 { 00363 Table checkTable = checkedTabels[expectedTableNames[i]]; 00364 Assert.AreEqual(expectedTableTypes[i], checkTable.Type); 00365 } 00366 00367 // Restore to the previos state 00368 for (int i = 0; i < expectedCount; i++) 00369 { 00370 returnCode = TableManagement.RemoveTable(checkedTabels[expectedTableNames[i]], ref errorMessage); 00371 } 00372 }*/ 00373 /*[Test] 00374 public void GetCustomTablesByTableGroup() 00375 { 00376 // Preparations 00377 int expectedCount = 3; 00378 string[] expectedTableNames = { "Test Table 1", "Test Table 2", "Test Table 3" }; 00379 string expectedGroupName = "Associated Equipments"; 00380 string[] expectedTableTypeVisibleNames = { "Single", "With History", "Authorization" }; 00381 Table.TableType[] expectedTableTypes = { 00382 Table.TableType.Single 00383 , Table.TableType.WithHistory 00384 , Table.TableType.Authorization 00385 }; 00386 bool[] expectedCustomTables = {true, true, false }; 00387 string errorMessage = ""; 00388 bool returnCode; 00389 00390 TableGroups tableGroups = TableManagement.TableGroups; 00391 TableGroup tableGroup = tableGroups[expectedGroupName]; 00392 00393 Table[] tables = new Table[expectedCount]; 00394 for (int i = 0; i < expectedCount; i++) 00395 { 00396 tables[i] = new Table(); 00397 tables[i].Name = expectedTableNames[i]; 00398 tables[i].TypeText = expectedTableTypeVisibleNames[i]; 00399 tables[i].CustomTable = expectedCustomTables[i]; 00400 TableManagement.AddTable(tables[i], tableGroup, ref errorMessage); 00401 } 00402 00403 // Test 00404 Tables checkedTabels = TableManagement.GetCustomTablesByTableGroup(tableGroup); 00405 00406 // Checks 00407 Assert.AreEqual(expectedCount - 1, checkedTabels.Count); 00408 for (int i = 0; i < expectedCount - 1; i++) 00409 { 00410 Table checkTable = checkedTabels[expectedTableNames[i]]; 00411 Assert.AreEqual(expectedTableTypes[i], checkTable.Type); 00412 } 00413 00414 // Restore to the previos state 00415 checkedTabels = TableManagement.GetTablesByTableGroup(tableGroup); 00416 for (int i = 0; i < expectedCount; i++) 00417 { 00418 returnCode = TableManagement.RemoveTable(checkedTabels[expectedTableNames[i]], ref errorMessage); 00419 } 00420 }*/ 00421 [Test] 00422 public void AddField() 00423 { 00424 /*// Preparations 00425 // Add Table 00426 string expectedTableName = "Test Table"; 00427 string expectedRelatedTableName = "Related Table"; 00428 string expectedGroupName = "Associated Equipments"; 00429 string expectedTableTypeVisibleName = "Single"; 00430 bool expectedCustomTable = true; 00431 Table.TableType expectedTableType = Table.TableType.Single; 00432 string errorMessage = ""; 00433 bool returnCode; 00434 TableGroups tableGroups = TableManagement.TableGroups; 00435 TableGroup tableGroup = tableGroups[expectedGroupName]; 00436 Table table = new Table(); 00437 table.Name = expectedTableName; 00438 table.TypeText = expectedTableTypeVisibleName; 00439 table.CustomTable = expectedCustomTable; 00440 TableManagement.AddTable(table, tableGroup, ref errorMessage); 00441 Table relatedTable = new Table(); 00442 relatedTable.Name = expectedRelatedTableName; 00443 relatedTable.TypeText = expectedTableTypeVisibleName; 00444 relatedTable.CustomTable = expectedCustomTable; 00445 TableManagement.AddTable(relatedTable, tableGroup, ref errorMessage); 00446 00447 string expectedFieldName = "Test Field"; 00448 string expectedLocalLanguageFieldName = "Тестовое поле"; 00449 string expectedFieldPurpose = "Field Purpose"; 00450 string expectedLocalLanguageFieldPurpose = "Назначение поля"; 00451 string expectedFieldTypeText = "Text"; 00452 Field.FieldType expectedFieldType = Field.FieldType.Text; 00453 string expectedFieldSizeText = "Large (below 256 chars)"; 00454 Field.FieldSize expectedFieldSize = Field.FieldSize.Large; 00455 string expectedNecessityTypeVisibleName = "Required"; 00456 Field.NecessityType expectedNecessityType = Field.NecessityType.Required; 00457 int expectedOrder = 10; 00458 bool expectedIsNameField = true; 00459 bool expectedSystemField = true; 00460 bool expectedVisibleOnForms = true; 00461 bool expectedUniqueValue = true; 00462 bool expectedNeedsTranslation = true; 00463 bool expectedMultiline = true; 00464 00465 Field field = new Field(); 00466 field.Name = expectedFieldName; 00467 field.FieldPurpose = expectedFieldPurpose; 00468 field.LocalLanguageFieldName = expectedLocalLanguageFieldName; 00469 field.LocalLanguageFieldPurpose = expectedLocalLanguageFieldPurpose; 00470 field.TypeText = expectedFieldTypeText; 00471 field.SizeText = expectedFieldSizeText; 00472 field.NecessityText = expectedNecessityTypeVisibleName; 00473 field.Order = expectedOrder; 00474 field.IsNameField = expectedIsNameField; 00475 field.SystemField = expectedSystemField; 00476 field.VisibleOnForms = expectedVisibleOnForms; 00477 field.UniqueValue = expectedUniqueValue; 00478 field.NeedsTranslation = expectedNeedsTranslation; 00479 field.Multiline = expectedMultiline; 00480 field.RelatedTable = relatedTable; 00481 00482 // Test 00483 returnCode = TableManagement.AddField(table, field, ref errorMessage); 00484 00485 // Checks 00486 Assert.IsTrue(returnCode); 00487 00488 Fields fields = TableManagement.GetFieldsByTable(table); 00489 Field checkField = fields[expectedFieldName]; 00490 00491 Assert.AreEqual(expectedFieldPurpose, checkField.FieldPurpose); 00492 Assert.AreEqual(expectedLocalLanguageFieldName, checkField.LocalLanguageFieldName); 00493 Assert.AreEqual(expectedLocalLanguageFieldPurpose, checkField.LocalLanguageFieldPurpose); 00494 Assert.AreEqual(expectedFieldType, checkField.Type); 00495 Assert.AreEqual(expectedFieldSize, checkField.Size); 00496 Assert.AreEqual(expectedNecessityType, checkField.Necessity); 00497 Assert.AreEqual(expectedOrder, checkField.Order); 00498 Assert.AreEqual(expectedIsNameField, checkField.IsNameField); 00499 Assert.AreEqual(expectedSystemField, checkField.SystemField); 00500 Assert.AreEqual(expectedVisibleOnForms, checkField.VisibleOnForms); 00501 Assert.AreEqual(expectedUniqueValue, checkField.UniqueValue); 00502 Assert.AreEqual(expectedNeedsTranslation, checkField.NeedsTranslation); 00503 Assert.AreEqual(expectedMultiline, checkField.Multiline); 00504 Assert.AreEqual(expectedRelatedTableName, checkField.RelatedTable.Name); 00505 Assert.AreEqual(expectedTableType, checkField.RelatedTable.Type); 00506 00507 // Restore to the previos state 00508 TableManagement.RemoveField(checkField, ref errorMessage); 00509 TableManagement.RemoveTable(table, ref errorMessage); 00510 TableManagement.RemoveTable(relatedTable, ref errorMessage);*/ 00511 } 00512 /*[Test] 00513 public void SaveField() 00514 { 00515 // Preparations 00516 // Add Table 00517 string expectedTableName = "Test Table"; 00518 string expectedGroupName = "Associated Equipments"; 00519 string expectedTableTypeVisibleName = "Single"; 00520 string errorMessage = ""; 00521 bool returnCode; 00522 TableGroups tableGroups = TableManagement.TableGroups; 00523 TableGroup tableGroup = tableGroups[expectedGroupName]; 00524 Table table = new Table(); 00525 table.Name = expectedTableName; 00526 table.TypeText = expectedTableTypeVisibleName; 00527 TableManagement.AddTable(table, tableGroup, ref errorMessage); 00528 00529 string initFieldName = "Test Field"; 00530 string initLocalLanguageFieldName = "Тестовое поле"; 00531 string initFieldPurpose = "Field Purpose"; 00532 string initLocalLanguageFieldPurpose = "Назначение поля"; 00533 string initFieldTypeText = "Text"; 00534 string initNecessityTypeVisibleName = "Required"; 00535 int initOrder = 10; 00536 bool initIsNameField = true; 00537 bool initSystemField = true; 00538 bool initVisibleOnForms = true; 00539 bool initUniqueValue = true; 00540 bool initNeedsTranslation = true; 00541 bool initMultiline = true; 00542 00543 Field field = new Field(); 00544 field.Name = initFieldName; 00545 field.FieldPurpose = initFieldPurpose; 00546 field.LocalLanguageFieldName = initLocalLanguageFieldName; 00547 field.LocalLanguageFieldPurpose = initLocalLanguageFieldPurpose; 00548 field.TypeText = initFieldTypeText; 00549 field.NecessityText = initNecessityTypeVisibleName; 00550 field.Order = initOrder; 00551 field.IsNameField = initIsNameField; 00552 field.SystemField = initSystemField; 00553 field.VisibleOnForms = initVisibleOnForms; 00554 field.UniqueValue = initUniqueValue; 00555 field.NeedsTranslation = initNeedsTranslation; 00556 field.Multiline = initMultiline; 00557 TableManagement.AddField(table, field, ref errorMessage); 00558 00559 string expectedFieldName = "Updated Test Field"; 00560 string expectedLocalLanguageFieldName = "Измененное тестовое поле"; 00561 string expectedFieldPurpose = "Updated Field Purpose"; 00562 string expectedLocalLanguageFieldPurpose = "Измененное назначение поля"; 00563 string expectedFieldTypeText = "Date"; 00564 Field.FieldType expectedFieldType = Field.FieldType.Date; 00565 Field.NecessityType expectedNecessityType = Field.NecessityType.Suggested; 00566 string expectedNecessityTypeVisibleName = "Suggested"; 00567 int expectedOrder = 5; 00568 bool expectedIsNameField = false; 00569 bool expectedSystemField = false; 00570 bool expectedVisibleOnForms = false; 00571 bool expectedUniqueValue = false; 00572 bool expectedNeedsTranslation = false; 00573 bool expectedMultiline = false; 00574 00575 // Set new values 00576 field.Name = expectedFieldName; 00577 field.FieldPurpose = expectedFieldPurpose; 00578 field.LocalLanguageFieldName = expectedLocalLanguageFieldName; 00579 field.LocalLanguageFieldPurpose = expectedLocalLanguageFieldPurpose; 00580 field.TypeText = expectedFieldTypeText; 00581 field.NecessityText = expectedNecessityTypeVisibleName; 00582 field.Order = expectedOrder; 00583 field.IsNameField = expectedIsNameField; 00584 field.SystemField = expectedSystemField; 00585 field.VisibleOnForms = expectedVisibleOnForms; 00586 field.UniqueValue = expectedUniqueValue; 00587 field.NeedsTranslation = expectedNeedsTranslation; 00588 field.Multiline = expectedMultiline; 00589 00590 // Test 00591 returnCode = TableManagement.SaveField(field, ref errorMessage); 00592 00593 // Checks 00594 Assert.IsTrue(returnCode); 00595 00596 Fields fields = TableManagement.GetFieldsByTable(table); 00597 Field checkField = fields[expectedFieldName]; 00598 00599 Assert.AreEqual(expectedFieldPurpose, checkField.FieldPurpose); 00600 Assert.AreEqual(expectedLocalLanguageFieldName, checkField.LocalLanguageFieldName); 00601 Assert.AreEqual(expectedLocalLanguageFieldPurpose, checkField.LocalLanguageFieldPurpose); 00602 Assert.AreEqual(expectedFieldType, checkField.Type); 00603 Assert.AreEqual(expectedNecessityType, checkField.Necessity); 00604 Assert.AreEqual(expectedOrder, checkField.Order); 00605 Assert.AreEqual(expectedIsNameField, checkField.IsNameField); 00606 Assert.AreEqual(expectedSystemField, checkField.SystemField); 00607 Assert.AreEqual(expectedVisibleOnForms, checkField.VisibleOnForms); 00608 Assert.AreEqual(expectedUniqueValue, checkField.UniqueValue); 00609 Assert.AreEqual(expectedNeedsTranslation, checkField.NeedsTranslation); 00610 Assert.AreEqual(expectedMultiline, checkField.Multiline); 00611 00612 // Restore to the previos state 00613 TableManagement.RemoveField(checkField, ref errorMessage); 00614 TableManagement.RemoveTable(table, ref errorMessage); 00615 } 00616 [Test] 00617 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))] 00618 public void RemoveField() 00619 { 00620 // Preparations 00621 // Add Table 00622 string expectedTableName = "Test Table"; 00623 string expectedGroupName = "Associated Equipments"; 00624 string expectedTableTypeVisibleName = "Single"; 00625 string errorMessage = ""; 00626 bool returnCode; 00627 TableGroups tableGroups = TableManagement.TableGroups; 00628 TableGroup tableGroup = tableGroups[expectedGroupName]; 00629 Table table = new Table(); 00630 table.Name = expectedTableName; 00631 table.TypeText = expectedTableTypeVisibleName; 00632 TableManagement.AddTable(table, tableGroup, ref errorMessage); 00633 00634 string expectedFieldName = "Test Field"; 00635 string expectedLocalLanguageFieldName = "Тестовое поле"; 00636 string expectedFieldPurpose = "Field Purpose"; 00637 string expectedLocalLanguageFieldPurpose = "Назначение поля"; 00638 string expectedFieldTypeText = "Text"; 00639 string expectedFieldSizeText = "Large (below 256 chars)"; 00640 string expectedNecessityTypeVisibleName = "Required"; 00641 int expectedOrder = 10; 00642 bool expectedIsNameField = true; 00643 bool expectedSystemField = true; 00644 bool expectedVisibleOnForms = true; 00645 bool expectedUniqueValue = true; 00646 bool expectedNeedsTranslation = true; 00647 bool expectedMultiline = true; 00648 00649 Field field = new Field(); 00650 field.Name = expectedFieldName; 00651 field.FieldPurpose = expectedFieldPurpose; 00652 field.LocalLanguageFieldName = expectedLocalLanguageFieldName; 00653 field.LocalLanguageFieldPurpose = expectedLocalLanguageFieldPurpose; 00654 field.TypeText = expectedFieldTypeText; 00655 field.SizeText = expectedFieldSizeText; 00656 field.NecessityText = expectedNecessityTypeVisibleName; 00657 field.Order = expectedOrder; 00658 field.IsNameField = expectedIsNameField; 00659 field.SystemField = expectedSystemField; 00660 field.VisibleOnForms = expectedVisibleOnForms; 00661 field.UniqueValue = expectedUniqueValue; 00662 field.NeedsTranslation = expectedNeedsTranslation; 00663 field.Multiline = expectedMultiline; 00664 TableManagement.AddField(table, field, ref errorMessage); 00665 00666 // Test 00667 returnCode = TableManagement.RemoveField(field, ref errorMessage); 00668 00669 // Checks 00670 Assert.IsTrue(returnCode); 00671 00672 // Check that field does not exist in table fields 00673 // Expected exception System.Collections.Generic.KeyNotFoundException 00674 Fields fields = TableManagement.GetFieldsByTable(table); 00675 try 00676 { 00677 Field checkField = fields[expectedFieldName]; 00678 } 00679 finally 00680 { 00681 // Restore to the previos state 00682 TableManagement.RemoveTable(table, ref errorMessage); 00683 } 00684 } 00685 [Test] 00686 public void GetFieldsByTable() 00687 { 00688 // Preparations 00689 // Add Table 00690 string expectedTableName = "Test Table"; 00691 string expectedGroupName = "Associated Equipments"; 00692 string expectedTableTypeVisibleName = "Single"; 00693 string errorMessage = ""; 00694 TableGroups tableGroups = TableManagement.TableGroups; 00695 TableGroup tableGroup = tableGroups[expectedGroupName]; 00696 Table table = new Table(); 00697 table.Name = expectedTableName; 00698 table.TypeText = expectedTableTypeVisibleName; 00699 TableManagement.AddTable(table, tableGroup, ref errorMessage); 00700 00701 string[] expectedFieldNames = { "Test Field 1", "Test Field 2", "Test Field 3" }; 00702 string[] expectedLocalLanguageFieldNames = { "Тестовое поле 1", "Тестовое поле 2", "Тестовое поле 3" }; 00703 string[] expectedFieldPurposes = { "Field Purpose 1", "Field Purpose 2", "Field Purpose 3" }; 00704 string[] expectedLocalLanguageFieldPurposes = { "Назначение поля 1", "Назначение поля 2", "Назначение поля 3" }; 00705 string[] expectedFieldTypesText = { "Text", "Date", "Lookup Plus Integer Value" }; 00706 Field.FieldType[] expectedFieldTypes = { Field.FieldType.Text, Field.FieldType.Date, Field.FieldType.LookupPlusIntegerValue }; 00707 Field.NecessityType[] expectedNecessityTypes = { Field.NecessityType.Required, Field.NecessityType.NotRequired, Field.NecessityType.Suggested }; 00708 string[] expectedNecessityTypeVisibleNames = { "Required", "Not Required", "Suggested" }; 00709 int[] expectedOrders = { 5, 10, 15 }; 00710 bool[] expectedIsNameFields = { true, false, true }; 00711 bool[] expectedSystemFields = { true, false, true }; 00712 bool[] expectedVisibleOnForms = { true, false, true }; 00713 bool[] expectedUniqueValues = { true, false, true }; 00714 bool[] expectedNeedsTranslations = { true, false, true }; 00715 bool[] expectedMultilines = { true, false, true }; 00716 00717 int expectedCount = expectedFieldNames.Length; 00718 Field[] fields = new Field[expectedCount]; 00719 for (int i = 0; i < expectedCount; i++) 00720 { 00721 fields[i] = new Field(); 00722 fields[i].Name = expectedFieldNames[i]; 00723 fields[i].FieldPurpose = expectedFieldPurposes[i]; 00724 fields[i].LocalLanguageFieldName = expectedLocalLanguageFieldNames[i]; 00725 fields[i].LocalLanguageFieldPurpose = expectedLocalLanguageFieldPurposes[i]; 00726 fields[i].TypeText = expectedFieldTypesText[i]; 00727 fields[i].NecessityText = expectedNecessityTypeVisibleNames[i]; 00728 fields[i].Order = expectedOrders[i]; 00729 fields[i].IsNameField = expectedIsNameFields[i]; 00730 fields[i].SystemField = expectedSystemFields[i]; 00731 fields[i].VisibleOnForms = expectedVisibleOnForms[i]; 00732 fields[i].UniqueValue = expectedUniqueValues[i]; 00733 fields[i].NeedsTranslation = expectedNeedsTranslations[i]; 00734 fields[i].Multiline = expectedMultilines[i]; 00735 00736 TableManagement.AddField(table, fields[i], ref errorMessage); 00737 } 00738 00739 // Test 00740 Fields checkFields = TableManagement.GetFieldsByTable(table); 00741 00742 // Checks 00743 Assert.AreEqual(expectedCount, checkFields.Count); 00744 00745 for (int i = 0; i < expectedCount; i++) 00746 { 00747 Field checkField = checkFields[expectedFieldNames[i]]; 00748 Assert.AreEqual(expectedFieldPurposes[i], checkField.FieldPurpose); 00749 Assert.AreEqual(expectedLocalLanguageFieldNames[i], checkField.LocalLanguageFieldName); 00750 Assert.AreEqual(expectedLocalLanguageFieldPurposes[i], checkField.LocalLanguageFieldPurpose); 00751 Assert.AreEqual(expectedFieldTypes[i], checkField.Type); 00752 Assert.AreEqual(expectedNecessityTypes[i], checkField.Necessity); 00753 Assert.AreEqual(expectedOrders[i], checkField.Order); 00754 Assert.AreEqual(expectedIsNameFields[i], checkField.IsNameField); 00755 Assert.AreEqual(expectedSystemFields[i], checkField.SystemField); 00756 Assert.AreEqual(expectedVisibleOnForms[i], checkField.VisibleOnForms); 00757 Assert.AreEqual(expectedUniqueValues[i], checkField.UniqueValue); 00758 Assert.AreEqual(expectedNeedsTranslations[i], checkField.NeedsTranslation); 00759 Assert.AreEqual(expectedMultilines[i], checkField.Multiline); 00760 } 00761 00762 // Restore to the previos state 00763 for (int i = 0; i < expectedCount; i++) 00764 { 00765 TableManagement.RemoveField(checkFields[expectedFieldNames[i]], ref errorMessage); 00766 } 00767 TableManagement.RemoveTable(table, ref errorMessage); 00768 }*/ 00769 [Test] 00770 public void GetFieldSizesByFieldType_DateTypeSizesCount() 00771 { 00772 // Preparations 00773 int expectedCount = 0; 00774 Field.FieldType expectedFieldType = Field.FieldType.Date; 00775 00776 // Test 00777 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00778 00779 // Checks 00780 Assert.AreEqual(expectedCount, fieldSizes.Count); 00781 } 00782 [Test] 00783 public void GetFieldSizesByFieldType_LookupPlusIntegerValueTypeSizesCount() 00784 { 00785 // Preparations 00786 int expectedCount = 0; 00787 Field.FieldType expectedFieldType = Field.FieldType.LookupPlusIntegerValue; 00788 00789 // Test 00790 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00791 00792 // Checks 00793 Assert.AreEqual(expectedCount, fieldSizes.Count); 00794 } 00795 [Test] 00796 public void GetFieldSizesByFieldType_LookupPlusScientificValueTypeSizesCount() 00797 { 00798 // Preparations 00799 int expectedCount = 0; 00800 Field.FieldType expectedFieldType = Field.FieldType.LookupPlusScientificValue; 00801 00802 // Test 00803 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00804 00805 // Checks 00806 Assert.AreEqual(expectedCount, fieldSizes.Count); 00807 } 00808 [Test] 00809 public void GetFieldSizesByFieldType_MultipleLookupTypeSizesCount() 00810 { 00811 // Preparations 00812 int expectedCount = 0; 00813 Field.FieldType expectedFieldType = Field.FieldType.MultipleLookup; 00814 00815 // Test 00816 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00817 00818 // Checks 00819 Assert.AreEqual(expectedCount, fieldSizes.Count); 00820 } 00821 [Test] 00822 public void GetFieldSizesByFieldType_NumericTypeSizesCount() 00823 { 00824 // Preparations 00825 int expectedCount = 5; 00826 Field.FieldType expectedFieldType = Field.FieldType.Numeric; 00827 00828 // Test 00829 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00830 00831 // Checks 00832 Assert.AreEqual(expectedCount, fieldSizes.Count); 00833 } 00834 [Test] 00835 public void GetFieldSizesByFieldType_SingleLookupTypeSizesCount() 00836 { 00837 // Preparations 00838 int expectedCount = 0; 00839 Field.FieldType expectedFieldType = Field.FieldType.SingleLookup; 00840 00841 // Test 00842 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00843 00844 // Checks 00845 Assert.AreEqual(expectedCount, fieldSizes.Count); 00846 } 00847 [Test] 00848 public void GetFieldSizesByFieldType_TextTypeSizesCount() 00849 { 00850 // Preparations 00851 int expectedCount = 4; 00852 Field.FieldType expectedFieldType = Field.FieldType.Text; 00853 00854 // Test 00855 FieldSizes fieldSizes = TableManagement.GetFieldSizesByFieldType(expectedFieldType); 00856 00857 // Checks 00858 Assert.AreEqual(expectedCount, fieldSizes.Count); 00859 } 00860 [Test] 00861 public void GetFieldSizesByFieldType_Large() 00862 { 00863 // Preparations 00864 int expectedID = 1; 00865 Field.FieldSize expectedSize = Field.FieldSize.Large; 00866 string expectedVisibleName = "Large (below 256 chars)"; 00867 Field.FieldType expectedFieldType = Field.FieldType.Text; 00868 00869 // Test 00870 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00871 00872 // Checks 00873 Assert.AreEqual(expectedID, fieldSizeData.ID); 00874 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00875 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00876 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00877 } 00878 [Test] 00879 public void GetFieldSizesByFieldType_Medium() 00880 { 00881 // Preparations 00882 int expectedID = 2; 00883 Field.FieldSize expectedSize = Field.FieldSize.Medium; 00884 string expectedVisibleName = "Medium (below 128 chars)"; 00885 Field.FieldType expectedFieldType = Field.FieldType.Text; 00886 00887 // Test 00888 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00889 00890 // Checks 00891 Assert.AreEqual(expectedID, fieldSizeData.ID); 00892 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00893 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00894 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00895 } 00896 [Test] 00897 public void GetFieldSizesByFieldType_Memo() 00898 { 00899 // Preparations 00900 int expectedID = 3; 00901 Field.FieldSize expectedSize = Field.FieldSize.Memo; 00902 string expectedVisibleName = "Memo (more then 255 chars)"; 00903 Field.FieldType expectedFieldType = Field.FieldType.Text; 00904 00905 // Test 00906 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00907 00908 // Checks 00909 Assert.AreEqual(expectedID, fieldSizeData.ID); 00910 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00911 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00912 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00913 } 00914 [Test] 00915 public void GetFieldSizesByFieldType_Small() 00916 { 00917 // Preparations 00918 int expectedID = 4; 00919 Field.FieldSize expectedSize = Field.FieldSize.Small; 00920 string expectedVisibleName = "Small (below 50 chars)"; 00921 Field.FieldType expectedFieldType = Field.FieldType.Text; 00922 00923 // Test 00924 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00925 00926 // Checks 00927 Assert.AreEqual(expectedID, fieldSizeData.ID); 00928 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00929 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00930 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00931 } 00932 [Test] 00933 public void GetFieldSizesByFieldType_Integer() 00934 { 00935 // Preparations 00936 int expectedID = 5; 00937 Field.FieldSize expectedSize = Field.FieldSize.Integer; 00938 string expectedVisibleName = "Integer (-2; -1; 0; 1; 2...)"; 00939 Field.FieldType expectedFieldType = Field.FieldType.Numeric; 00940 00941 // Test 00942 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00943 00944 // Checks 00945 Assert.AreEqual(expectedID, fieldSizeData.ID); 00946 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00947 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00948 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00949 } 00950 [Test] 00951 public void GetFieldSizesByFieldType_Rational() 00952 { 00953 // Preparations 00954 int expectedID = 6; 00955 Field.FieldSize expectedSize = Field.FieldSize.Rational; 00956 string expectedVisibleName = "Rational (-2.5; 0.0; 2.5)"; 00957 Field.FieldType expectedFieldType = Field.FieldType.Numeric; 00958 00959 // Test 00960 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00961 00962 // Checks 00963 Assert.AreEqual(expectedID, fieldSizeData.ID); 00964 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00965 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00966 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00967 } 00968 [Test] 00969 public void GetFieldSizesByFieldType_Scientific() 00970 { 00971 // Preparations 00972 int expectedID = 7; 00973 Field.FieldSize expectedSize = Field.FieldSize.Scientific; 00974 string expectedVisibleName = "Scientific Number"; 00975 Field.FieldType expectedFieldType = Field.FieldType.Numeric; 00976 00977 // Test 00978 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00979 00980 // Checks 00981 Assert.AreEqual(expectedID, fieldSizeData.ID); 00982 Assert.AreEqual(expectedSize, fieldSizeData.Type); 00983 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 00984 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 00985 } 00986 [Test] 00987 public void GetFieldSizesByFieldType_TimeInterval() 00988 { 00989 // Preparations 00990 int expectedID = 8; 00991 Field.FieldSize expectedSize = Field.FieldSize.TimeInterval; 00992 string expectedVisibleName = "Time Interval"; 00993 Field.FieldType expectedFieldType = Field.FieldType.Numeric; 00994 00995 // Test 00996 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 00997 00998 // Checks 00999 Assert.AreEqual(expectedID, fieldSizeData.ID); 01000 Assert.AreEqual(expectedSize, fieldSizeData.Type); 01001 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 01002 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 01003 } 01004 [Test] 01005 public void GetFieldSizesByFieldType_Year() 01006 { 01007 // Preparations 01008 int expectedID = 9; 01009 Field.FieldSize expectedSize = Field.FieldSize.Year; 01010 string expectedVisibleName = "Year"; 01011 Field.FieldType expectedFieldType = Field.FieldType.Numeric; 01012 01013 // Test 01014 Field.FieldSizeData fieldSizeData = TableManagement.GetFieldSizesByFieldType(expectedFieldType)[expectedVisibleName]; 01015 01016 // Checks 01017 Assert.AreEqual(expectedID, fieldSizeData.ID); 01018 Assert.AreEqual(expectedSize, fieldSizeData.Type); 01019 Assert.AreEqual(expectedVisibleName, fieldSizeData.VisibleName); 01020 Assert.AreEqual(expectedFieldType, fieldSizeData.FieldType); 01021 } 01022 #endregion 01023 [TearDown] 01024 public void Finally() 01025 { 01026 //TestUtilities.TruncateTable("Field"); 01027 //TestUtilities.TruncateTable("Table"); 01028 TestUtilities.DeleteTestTables(); 01029 } 01030 } 01031 }